package com.problem.leetcode;

import java.util.HashSet;

/**
 * 解决方法:
 * 1.使用Hashset
 * 2.原地排序，检验相邻元素是否相同
 */
public class Problem271 {
    public boolean containsDuplicate(int[] nums) {
        if (nums == null || nums.length == 1) {
            return false;
        }

        HashSet<Integer> set = new HashSet<>();
        for (Integer ele : nums) {
            if(set.contains(ele)) {
                return true;
            }else {
                set.add(ele);
            }
        }
        return false;
    }

    public static void main(String[] args) {
        new Problem271().containsDuplicate(new int[]{1});
    }

}
